package net.dianpin.util;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.log4j.Logger;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**关于DAO操作的一些方法
 * Created by lei on 2014/6/13.
 */
public class DAOUtil {

    private static Logger logger = Logger.getLogger(DAOUtil.class);

    private static ApplicationContext applicationContext = null;
    private static SqlSessionFactory sqlSessionFactory = null;
    private static SqlSession sqlSession = null;

    static {
        applicationContext = new ClassPathXmlApplicationContext("application_context.xml");
        sqlSessionFactory = applicationContext.getBean("sqlSessionFactory",SqlSessionFactory.class);
        sqlSession = sqlSessionFactory.openSession();
    }

    //根据传入的Mapper，获取对应的Mapper实例
    public static <T> Object getMapperInstance(T a){
        return sqlSession.getMapper((Class)a);
    }
}
